#coding:utf8
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer,BadSignature
from django.conf import settings


def get_verify_url(id,email):

    s = Serializer(settings.SECRET_KEY,3600)

    token = s.dumps({
        'id':id,
        'email':email
    })

    url = 'http://www.meiduo.site:8080/success_verify_email.html?token=' + token.decode()

    return url


def check_verify_token(token):

    s = Serializer(settings.SECRET_KEY,3600)

    try:
        result = s.loads(token)
    except BadSignature:
        return None
    else:
        # {id:xxx,email:xxx}
        return result.get('id')

